const OSS = require('ali-oss')

const client = new OSS({
  region: process.env.VUE_APP_OSS_REGION,
  accessKeyId: process.env.VUE_APP_OSS_KEY,
  accessKeySecret: process.env.VUE_APP_OSS_SECRET,
  bucket: process.env.VUE_APP_OSS_BUCKET
})

const oss = {
  data () {
    return {
    }
  },
  methods: {
    // 上传本地文件
     async putObject (objectKey, file) {
       try {
         // object-key可以自定义为文件名（例如file.txt）或目录（例如abc/test/file.txt）的形式，实现将文件上传至当前Bucket或Bucket下的指定目录。
         const result = await client.put(objectKey, file)
         console.log(result)
         return result
       } catch (e) {
         console.log(e)
       }
       return null
     },

    // 删除文件
    async delete (objectKey) {
      try {
        const result = await client.delete(objectKey)
        console.log(result)
      } catch (e) {
        console.log(e)
      }
    }
  }
}

export default oss
